//
//  HWyaoqinghaoyoujiemianViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2020/12/23.
//  Copyright © 2020 Chendaobin. All rights reserved.
//

#import "HWyaoqinghaoyoujiemianViewController.h"
#import "HWYouxiFenxiangGameView.h"
#import "HWerweiMaFenXiangView.h"
#import "HWMoWanVouchersViewController.h"
#import "HWyaoqingguizetankuanView.H"

@interface HWyaoqinghaoyoujiemianViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(strong,nonatomic)UITableView *mainaTableVie;
@property(strong,nonatomic)UIView *maintableaddheadeView;
@property(strong,nonatomic)UIImageView *yaoqingimageView;
@property(strong,nonatomic)UIView *yaoqingView;
@property(strong,nonatomic)UIImageView *fenxiangImageView;
@property(strong,nonatomic)UIImageView *erweimaImageView;
@property(strong,nonatomic)UIButton  *fenxiangbutong;
@property(strong,nonatomic) UIImageView *yaoqinghaoyouImageView;
@property(strong,nonatomic) NSMutableArray *shuzuMuArr; // 存储的三个label
@property(strong,nonatomic) NSDictionary *dataDic;
@property(strong,nonatomic) HWYouxiFenxiangGameView *fenxiangView; // 分享UIview





@end

@implementation HWyaoqinghaoyoujiemianViewController





-(UITableView *)mainaTableVie {

    if  (_mainaTableVie == nil) {

      //   _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, -StatusBarHeight, kScreenW, kScreenH-TabBarHeight) style:UITableViewStylePlain];
        
         _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainaTableVie.backgroundColor = [UIColor clearColor];
         _mainaTableVie.backgroundColor = RGB(73, 74, 86);
        
         
        
        
        
    }
    return   _mainaTableVie ;

}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    NSLog(@"1111111");
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
     NSLog(@"22222222");
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupUI];
    
    [self shezhiyixietupianView];
    
    // 发送网路请求
    [self sendNetworkRequest];
    
    
}



- (void)sendNetworkRequest {
    
    NSString *userID = [HWLocallyStoredData getLoginUserID];
    int  t =  [WMUtil getRandomNumber:101 to:998];
    NSString *tStr = [NSString stringWithFormat:@"%ld%d",[WMUtil getTimeSp],t];
    NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
    NSString *signMD5 = [WMUtil md5HexDigest:sign];
    
    
    
    
    
    NSDictionary *parametes = @{
                           
                                @"ios" : @"1",
                                @"uid" :userID,
                                @"t" :tStr,
                                @"sign": signMD5,
                                @"member_id":[HWLocallyStoredData getCode],
                                @"language":[HWjianzhiduiObject returnLanguageAcquisition],
                                
                                };
  
    
    [HWWebUtils do4GetWithParameters:parametes  hiddenparameterStr:HW_invite progress:nil success:^(id response) {
        
      
        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
     //   [MBProgressHUD hideHUD];
        
        
        if ([codeStr intValue] == 1) {
         
            self.dataDic = response[@"data"];
            
         //    [self qingqiushezhiyixieshuju];
            [self shuxingjimian];
            
            
            
            

        } else {
            
             [MBProgressHUD  showError:response[@"message"]];
            
        }
        
        
        NSLog(@"%@",response);
        
        
    } failure:^(NSString *error) {
      
        [MBProgressHUD  showError:@"加载失败"];
        
    }];
    
    
    
    
    
    
    
    
    
}


//刷新界面
-(void)shuxingjimian  {
    
    
    
    [self.erweimaImageView sd_setImageWithURL:[NSURL URLWithString:self.dataDic[@"qrcode"]] placeholderImage:nil];
    
    
    UILabel  *labe1 =    self.shuzuMuArr[0];
    
    UILabel  *labe2 =    self.shuzuMuArr[1];
    UILabel  *labe3 =    self.shuzuMuArr[2];
    
    labe1.text = [NSString stringWithFormat:@"%@",self.dataDic[@"num"]];
    labe2.text = [NSString stringWithFormat:@"%@",self.dataDic[@"coin"]];
    labe3.text = [NSString stringWithFormat:@"%@",self.dataDic[@"points"]];
    
    NSMutableArray *shuzu = [[NSMutableArray alloc]init];
    NSString *invite_codeStr =    [NSString stringWithFormat:@"%@",self.dataDic[@"invite_code"]];
 //    invite_codeStr = @"doopjo";
    
    for (int i = 0 ; i <  [invite_codeStr length]; i++) {
        [shuzu addObject:[NSString stringWithFormat:@"%C", [invite_codeStr characterAtIndex:i]]];
    }
    
    
    
    
    for (int i =0 ; i < shuzu.count; i++) {
        
        UILabel  *qinglabel = [[UILabel alloc] initWithFrame:CGRectMake(28+ 28*i+i*3, 45+8, 28, 30)];
        qinglabel.text =shuzu[i];
             qinglabel.textColor = RGB(68, 68, 68);
             qinglabel.font = [UIFont systemFontOfSize:16];
             qinglabel.textAlignment = NSTextAlignmentCenter;
             qinglabel.backgroundColor = RGB(238, 238, 238);
             qinglabel.layer.cornerRadius = 3;
             qinglabel.layer.masksToBounds = YES;
             [self.yaoqingView addSubview:qinglabel];
        
         
    }
    
     
     
    
    
 
    
    
    
    
    
    
    
    
}





// 设置uI
- (void)setupUI {
    
    
    
    [self.view addSubview:self.mainaTableVie];
    
    // self.view.backgroundColor =  [UIColor bm_colorGradientChangeWithSize:CGSizeMake(self.view.width, self.view.height) direction:IHGradientChangeDirectionVertical startColor:RGB(73, 74, 86) endColor:RGB(32, 32, 42)];
    self.view.backgroundColor =  RGB(73, 74, 86);
    [self addheadeview];
    
    
}



- (void)addheadeview  {
    
    
    
    
    self.maintableaddheadeView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 900)];
    
    
  //   self.maintableaddheadeView.backgroundColor=  [UIColor bm_colorGradientChangeWithSize:CGSizeMake(self.view.width, 800) direction:IHGradientChangeDirectionVertical startColor:RGB(73, 74, 86) endColor:RGB(32, 32, 42)];
    self.maintableaddheadeView.backgroundColor = RGB(73, 74, 86);
    
    self.mainaTableVie.tableHeaderView =  self.maintableaddheadeView;
    
    
    
    
    UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenW-100,10, 90, 20)];
               //     nameLabel.text = fanlilistArr[i];
        //  nameLabel.backgroundColor =  RGB(248, 119, 6);
         nameLabel.backgroundColor = [UIColor clearColor];
          nameLabel.textAlignment = NSTextAlignmentCenter;
          nameLabel.font = [UIFont systemFontOfSize:15];
          nameLabel.textColor = RGB(255, 255, 255);
     //     nameLabel.layer.cornerRadius = 8;
     //     nameLabel.layer.masksToBounds = YES;
          nameLabel.text = @"邀请规则";
    nameLabel.text =  [HWjianzhiduiObject keylocalization:@"邀请规则"];
    
    nameLabel.userInteractionEnabled = YES;
        [ self.maintableaddheadeView addSubview:nameLabel];
    
    
    UITapGestureRecognizer *youqingtap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(yaoqinggui)];

    [nameLabel    addGestureRecognizer:youqingtap];
    
    
      
      
      UIButton *fanhuiBut = [UIButton buttonWithType:UIButtonTypeCustom];
      fanhuiBut.frame = CGRectMake(10, 0 , 40, 40);
      fanhuiBut.backgroundColor = [UIColor  clearColor];
      [fanhuiBut setImage:[UIImage imageNamed:@"fanhuijiemianIco"] forState:UIControlStateNormal];
      [fanhuiBut addTarget:self action:@selector(fanhuiButTap) forControlEvents:UIControlEventTouchUpInside];
      [ self.maintableaddheadeView  addSubview:fanhuiBut];
    
    
    
    
    
    
   //  UIPasteboard
    
 
    
    
    
}



// 邀请界面

- (void)yaoqinggui {
  
    
    
    
    
    NSLog(@"ckjjjjc");
    
    HWyaoqingguizetankuanView *xiaohaoview = [[HWyaoqingguizetankuanView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
    xiaohaoview.noteStr = [NSString stringWithFormat:@"%@",self.dataDic[@"note"]];
                           
                           
    [kKeyWindow addSubview:xiaohaoview];
    
    
    
}


- (void)fanhuiButTap {
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
    
    
}



// 点击分享按钮
- (void)buttonTapdfd:(UIButton *)sender  {
    
    
//    HWYouxiFenxiangGameView *FenXiang = [[HWYouxiFenxiangGameView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
//    //  FenXiang.delegate = self;
//      self.fenxiangView = FenXiang;
//      [kKeyWindow addSubview:FenXiang];
//
//
//      NSString *iocSt = [NSString stringWithFormat:@"%@",self.dataDic[@"link"]];
//      NSURL *url = [NSURL URLWithString:iocSt];
//      [self.fenxiangView.qrcodeImageView sd_setImageWithURL:url completed:nil];
//
//
    
    
    HWerweiMaFenXiangView  *fenxiang = [[HWerweiMaFenXiangView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
         fenxiang.urlStr = [NSString stringWithFormat:@"%@",self.dataDic[@"link"]];
         [kKeyWindow addSubview:fenxiang];
         
    
    
}






- (void)shezhiyixietupianView {
    
    
    self.yaoqingimageView = [[UIImageView alloc]initWithFrame:CGRectMake((kScreenW-203)/2, 44+20, 203, 127)];
    self.yaoqingimageView.image = [UIImage imageNamed:@"yaoqingjifenshitu"];
    [self.maintableaddheadeView addSubview:self.yaoqingimageView];
    
    self.yaoqingView = [[UIView alloc]initWithFrame:CGRectMake(12, self.yaoqingimageView.bottom+15, kScreenW-24, 103)];
    self.yaoqingView.backgroundColor = RGB(255, 255, 255);
    self.yaoqingView.layer.cornerRadius = 12;
    self.yaoqingView.layer.masksToBounds = YES;
    [self.maintableaddheadeView addSubview:self.yaoqingView];
    
     UILabel *yaoqingmalabel = [[UILabel alloc]initWithFrame:CGRectMake(28,20,200, 25)];
     yaoqingmalabel.text = @"我的邀请码";
    
    yaoqingmalabel.text = [HWjianzhiduiObject keylocalization:@"我的邀请码"];
    
     yaoqingmalabel.textColor = RGB(68, 68, 68);
     yaoqingmalabel.font = [UIFont systemFontOfSize:17];
     yaoqingmalabel.textAlignment = NSTextAlignmentLeft;
     [self.yaoqingView addSubview:yaoqingmalabel];
    

      
    
//      UILabel  *qinglabel = [[UILabel alloc] initWithFrame:CGRectMake(28, 45+8, 28, 30)];
//      qinglabel.text = @"S";
//      qinglabel.textColor = RGB(68, 68, 68);
//      qinglabel.font = [UIFont systemFontOfSize:16];
//      qinglabel.textAlignment = NSTextAlignmentCenter;
//      qinglabel.backgroundColor = RGB(238, 238, 238);
//      qinglabel.layer.cornerRadius = 3;
//      qinglabel.layer.masksToBounds = YES;
//      [self.yaoqingView addSubview:qinglabel];
//    
    
          UIButton *fuzhibBut = [UIButton buttonWithType:UIButtonTypeCustom];
         // kScreenW-24-60-15
         fuzhibBut.frame = CGRectMake(kScreenW-24-60-15,  56, 60, 24);
        fuzhibBut.backgroundColor =  RGB(246, 106, 5);
       //   [fanhuiBut setImage:[UIImage imageNamed:@"fanhuijiemianIco"] forState:UIControlStateNormal];
         [fuzhibBut addTarget:self action:@selector(fuzhiButTap) forControlEvents:UIControlEventTouchUpInside];
         fuzhibBut.layer.cornerRadius = 12;
         fuzhibBut.layer.masksToBounds = YES;
         [fuzhibBut setTitle:@"复制" forState:UIControlStateNormal];
    
         [fuzhibBut setTitle: [HWjianzhiduiObject keylocalization:@"复制"] forState:UIControlStateNormal];
         [ self.yaoqingView  addSubview:fuzhibBut];
       
       
    
    
    
  
    
    
    
    
    
    
    
    
    self.fenxiangImageView  = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenW-304)/2, self.yaoqingView.bottom+20, 304, 73)];
    self.fenxiangImageView.image = [UIImage imageNamed:@"fengxiangimage"];
    [self.maintableaddheadeView  addSubview:self.fenxiangImageView];
    
    
    
    
    self.erweimaImageView = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenW-120)/2,  self.fenxiangImageView.bottom+20, 120, 120)];
    self.erweimaImageView.backgroundColor = [UIColor redColor];
    [self.maintableaddheadeView addSubview:self.erweimaImageView];
    
    
    // 二维码
    UILabel *changanerweimalabel = [[UILabel alloc]initWithFrame:CGRectMake(0,self.erweimaImageView.bottom+10,kScreenW, 17)];
    changanerweimalabel.text = @"长按二维码图片保存可分享";
    changanerweimalabel.text = [HWjianzhiduiObject keylocalization: @"长按二维码图片保存可分享"];
    
    changanerweimalabel.textColor = [UIColor whiteColor];
    changanerweimalabel.font = [UIFont systemFontOfSize:12];
    changanerweimalabel.textAlignment = NSTextAlignmentCenter;
    [self.maintableaddheadeView  addSubview:changanerweimalabel];
    
    // 分享 BUtton 按钮
    
    
    NSString *fenxian = [HWjianzhiduiObject keylocalization:@"分享给好友"];
    
    UIButton *butt  = [UIButton setButtonWithFrame:CGRectMake( 32, changanerweimalabel.bottom+10 , kScreenW -64, 44) Title:fenxian Image:@"fenxiangicon" Font:13 Color:RGB(255, 255, 255) Target:self Selector:@selector(buttonTapdfd:)];
    
        [butt layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:4];
       // butt.backgroundColor = [UIColor redColor];
      butt.backgroundColor = RGB( 246, 106, 5);
    butt.layer.cornerRadius = 22;
    butt.layer.masksToBounds = YES;
    [self.maintableaddheadeView addSubview:butt];
    
    
    
    
    self.yaoqinghaoyouImageView = [[UIImageView alloc]initWithFrame:CGRectMake((kScreenW-365)/2, butt.bottom+20, 365, 108)];
    self.yaoqinghaoyouImageView.image = [UIImage imageNamed:@"beijingsghitu"];
 //    self.yaoqinghaoyouImageView.backgroundColor = [UIColor redColor];
    [self.maintableaddheadeView addSubview:self.yaoqinghaoyouImageView ];
    
    
    self.shuzuMuArr = [[NSMutableArray alloc] init];
    for (int i = 0 ; i < 3; i++) {
        
        
         UILabel *fenxianlabel = [[UILabel alloc]initWithFrame:CGRectMake(i*365/3, 40, 365/3, 45)];
        fenxianlabel.text = @"10";
        fenxianlabel.font = [UIFont systemFontOfSize:20];
        fenxianlabel.textColor = RGB(246, 106, 5);
        fenxianlabel.textAlignment =  NSTextAlignmentCenter;
        fenxianlabel.backgroundColor = [UIColor clearColor];
        [self.yaoqinghaoyouImageView addSubview:fenxianlabel];
        
        [self.shuzuMuArr addObject:fenxianlabel];
        
        
    
        
    }
    
    
    
    UIButton *yaoqingjilu = [UIButton buttonWithType:UIButtonTypeCustom];
   // kScreenW-24-60-15
    yaoqingjilu.frame = CGRectMake(32,  self.yaoqinghaoyouImageView.bottom+15, kScreenW -64, 44);
    yaoqingjilu.backgroundColor =  RGB(246, 106, 5);
 //   [fanhuiBut setImage:[UIImage imageNamed:@"fanhuijiemianIco"] forState:UIControlStateNormal];
   [yaoqingjilu addTarget:self action:@selector(yaoqingjilu) forControlEvents:UIControlEventTouchUpInside];
    yaoqingjilu.layer.cornerRadius = 22;
    yaoqingjilu.layer.masksToBounds = YES;
    
    NSString *yaoqingli = [HWjianzhiduiObject keylocalization:@"邀请记录"];
    
    
   [yaoqingjilu setTitle:yaoqingli  forState:UIControlStateNormal];
    yaoqingjilu.titleLabel.font = [UIFont systemFontOfSize:14];
    
    
    [self.maintableaddheadeView  addSubview:yaoqingjilu];
 
 
    
    
    
    
    
    
}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
     
    
    return 0 ;
    
    
    
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellID = @"cellId";

    UITableViewCell  *cell =  [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (!cell) {
        cell =  [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        
        
        
    }
    
    
    cell.selectionStyle =  UITableViewCellSelectionStyleNone;
   
    return  cell;
    
    
    
}




- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 240;
    
    
    
}







#pragma mark --------- fuzhi

- (void)fuzhiButTap {
    
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = self.dataDic[@"invite_code"];
    
    [MBProgressHUD showError:@"复制成功"];
    
    
}





- (void)yaoqingjilu  {
    
    
    HWMoWanVouchersViewController *yao =  [[HWMoWanVouchersViewController alloc]init];
   
    //  self.dataDic[@""]
    [self.navigationController  pushViewController:yao animated:YES];
    
    
    
    
}

 
@end
